package org.example.slave.packet;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.SneakyThrows;
import org.example.slave.util.LengthCodedStringReader;

import java.util.ArrayList;
import java.util.List;

/**
 * @author dingrui
 * @since 2022/2/16
 * @description
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class RowDataPacket extends PacketWithHeader {

    private List<String> columns = new ArrayList<>();

    @SneakyThrows
    @Override
    public void fromBytes(byte[] data) {
        int index = 0;
        LengthCodedStringReader reader = new LengthCodedStringReader(null, index);
        do {
            getColumns().add(reader.readLengthCodedString(data));
        } while (reader.getIndex() < data.length);
    }
}
